<?php
namespace Web\Controller;
use Think\Controller;
class WebUserController extends Controller {

    public function _initialize(){  
        header("Content-Type: text/html; charset=utf-8");

    } 

    public function _empty($name){
        $this->nul($name);
    }
    
    /**
     * 注意 city方法 本身是 protected 方法
     * @param  [type] $name [description]
     * @return [type]       [description]
     */
    protected function nul($name){
        //和$name这个城市相关的处理
         echo "<h1>404</h1>";
         echo "没有这个地址:".$name;
    }
    /**
     * 企业注册分享码
     */
    public function qiye_signup(){
        if($_SESSION['user']['web_type']==0 || $_SESSION['user']['web_type']==1){
            $qudao_id=$_SESSION['user']['web_id']+1500000;
        }
        elseif ($_SESSION['user']['web_type']==2) {
            $qudao_id=$_SESSION['user']['web_id']+500001;
        }     
        $appid=$_SESSION['wechat_data'][1]['appid'];
        $appsecret=$_SESSION['wechat_data'][1]['appsecret'];
        $api=new \Com\WechatAuth($appid,$appsecret);
        $res=$api->qrcodeCreate($qudao_id);
        $msg['message']="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$res['ticket'];
        $this->assign('msg',$msg['message']);
        /*******佣金百分比********/
        $yj_where['x.p_u_id']=session('user.p_u_id');
        $yj=M('manage_yj')
            ->alias('k')
            ->join('bm_web_user x ON k.uid=x.p_u_id','LEFT')
            ->where($yj_where)
            ->group('yj_id')
            ->field('yj_pre')
            ->select();
        $kl=0;
        foreach ($yj as $key0 => $value0) {
            $arr[$kl]=$value0['yj_pre'];
            $kl++;
        }
        $new_arr=explode('%',implode('',$arr));
        unset($new_arr[count($new_arr)-1]);
        $pre_new=0;
        foreach ($new_arr as $key => $value) {
            $pre_new+=$value;
        }
        if($pre_new>0){
            $pre_new.='%';
            $this->assign('yjpre',$pre_new);
        }
        /*******佣金百分比********/


        $this->display();
    }
    /**
     * 开始评估
     */
    public function new_pingu(){
        /**********渠道类型*********************/
        $where['qudao_pro_id']=$_SESSION['user']['web_pro_id'];
        $where['qudao_city_id']=$_SESSION['user']['web_city_id'];
        $qudao = M('Qudao')->where($where)->group('qudao_type')->select();
        /**********渠道类型*********************/

        /**********标签渲染*********************/
        $where_dalei['f_id']=0;
        $biaoqian=M('biaoqian')->where($where_dalei)->select();
        foreach ($biaoqian as $key => $value) {
            $where_dalei_xiaolei['f_id']=$value['id'];
            $biaoqian[$key]['xb']=M('biaoqian')->where($where_dalei_xiaolei)->select();
        }
        /**********标签渲染*********************/
        /***************开始链表存储处理客户资料***********************/
        $kehu['kehu_old']=$_POST['kehu_old'];
        $kehu_id=M('web_user_data')->data($kehu)->add();
        $my_kuhu=M('web_user_data')->where('c_id='.$kehu_id)->find();
        session('my_kuhu',$my_kuhu);
        /***************开始链表存储处理客户资料***********************/

        /***************开始链表存储处理四表关联处理***********************/
        $lccdc_id['c_id']=$kehu_id;
        $lccdc_id['web_id']=session('user.web_id');
        $lccdc=M('lccdc')->data($lccdc_id)->add();
        $my_lccdc=M('lccdc')->where('lccdc_id='.$lccdc)->find();
        session('my_lccdc',$my_lccdc);
        /***************开始链表存储处理四表关联处理***********************/

        //dump(session());
        $this->assign('biaoqian',$biaoqian);
        $this->assign('qudao_list',$qudao);
        $this->display();
    }
    /**
     * ajax_获取大小类关联数据
     */
    public function ajax_biaoqina_dx(){
        /**********标签渲染*********************/
        $where_dalei['f_id']=0;
        $biaoqian=M('biaoqian')->where($where_dalei)->select();
        foreach ($biaoqian as $key => $value) {
            $where_dalei_xiaolei['f_id']=$value['id'];
            $biaoqian[$key]['xb']=M('biaoqian')->where($where_dalei_xiaolei)->select();
        }
        /**********标签渲染*********************/
        $this->ajaxReturn($biaoqian);
    }
    /**
     * 通过商品id获取利息个额度
     */
    public function ajax_leaxnm(){
        if(IS_AJAX){
          if($_REQUEST['gid']){
              $where_link['b.id']=$_POST['gid']?$_POST['gid']:$_GET['gid'];
              $link_data=M('lx')
                         ->alias('a')
                         ->join('bm_goods b ON a.g_id=b.id','LEFT')
                         ->field('min(min_lx) as new_min_lx,max(max_lx) as new_max_lx,min(min_ed) as new_min_ed,max(max_ed) as new_max_ed,b.id as goods_id')
                         ->group('b.id')
                         ->where($where_link)
                         ->find();
              $msg['code']=1;
              $msg['message']='查询成功';
              $msg['data']=$link_data;
          }
          else{
              $msg['code']=2;
              $msg['message']='条件不存在';

          }
        }
        else{
              $msg['code']='3';
              $msg['message']='传输方式有无请用ajax请求';

        }
        $this->ajaxReturn($msg);
    }
    /**
     * ajax获取用户信息web用户
     */
    public function ajax_web_id_data(){
        if(IS_AJAX){
          if($_REQUEST['web_id']){
              $where_link['web_id']=$_POST['web_id']?$_POST['web_id']:$_GET['web_id'];
              $user=M('web_user')->where($where_link)->find();
              $user['region_web_pro_id']=re_region_address($user['web_pro_id']);
              $user['region_web_city_id']=re_region_address($user['web_city_id']);
              $user['region_web_area_id']=re_region_address($user['web_area_id']);
              $msg['code']=1;
              $msg['message']='查询成功';
              $msg['data']=$user;
              $msg['you_data']=$_GET;
          }
          else{
              $msg['code']=2;
              $msg['message']='条件不存在';
              $msg['you_data']=$_GET;

          }
        }
        else{
              $msg['code']='3';
              $msg['message']='传输方式有无请用ajax请求';

        }
        $this->ajaxReturn($msg);
    }
    /**
     * ajax异步处理数据new评估
     */
    public function ajax_new_pingu(){

            if(IS_AJAX&&IS_POST){
                /**********渠道类型*********************/
                $where['qudao_city_id']=re_region($_POST['web_city_id'])?re_region($_POST['web_city_id']):"10258";
                $qudao = M('Qudao')->where($where)->group('qudao_type')->field('qudao_type')->select();
                /**********渠道类型*********************/
                $where_link['qudao_id']=array('gt','0');
                $where_link['qudao_type']=array('gt','0');

                $link_data=M('lx')
                           ->alias('a')
                           ->join('bm_goods b ON a.g_id=b.id','RIGHT')
                           ->join('bm_goods_foundation c ON b.gx_id=c.gx_id','RIGHT')
                           ->join('bm_qudao d ON c.dtypename = d.qudao_id','RIGHT')
                           ->field('min(min_lx) as new_min_lx,max(max_lx) as new_max_lx,min(min_ed) as new_min_ed,max(max_ed) as new_max_ed,d.qudao_id,d.qudao_type,d.qudao_id,c.gx_id')
                           ->group('qudao_type')
                           ->where($where_link)
                           ->select();
                $link_data=json_decode(str_replace('null','"0.00"',json_encode($link_data)),true);    
                foreach ($qudao as $y => $e) {
                   foreach ($link_data as $ey => $ue) {
                      if($e['qudao_type']==$ue['qudao_type']){
                         $qudao[$y]['m_data']=$ue;
                         break;
                      }
                   }
                }
                /**********标签渲染*********************/

                $xiaolei_arr=M('biaoqian')->where('type=0')->select();
                $out_i=0;
                foreach ($xiaolei_arr as $key => $value) {
                    $goods_arr_where['cp_temp']=array('LIKE',"%".$value['id']."%");
                    $goods_arr=M('goods')->where($goods_arr_where)->select();
                    foreach ($goods_arr as $k => $v) {
                        $where_arr['u_id']=$v['u_id'];
                        $where_arr['u_city_id']=re_region($_POST['web_city_id'])?re_region($_POST['web_city_id']):"10258";
                        $and[$out_i]=M('user')->where($where_arr)->find();
                        if($and[$out_i]){
                                $arr[$out_i]=$value;
                                $arr[$out_i]['f_id']=M('biaoqian')->where('id='.$value['f_id'])->find();
                                $out_i++; 
                        }

                    }
                }
                $new_arr=array_unique($arr);
                $msg['code']=1;
                $msg['message']='查询成功';
                $msg['data']=array($arr,$qudao);
            }
            else{
                $msg['code']=2;
                $msg['message']='查询方式错误';
            }
      $this->ajaxReturn($msg);
    }

    /**
     * new评估辅助1
     * @DateTime:    [2018-03-13 11:12:25]
     */
    public function new_fz_qudao(){
                $qudao = M('Qudao')->group('qudao_type')->select();
                /**********渠道类型*********************/
                $where_link['qudao_id']=array('gt','0');
                $where_link['qudao_type']=array('gt','0');

                $link_data=M('lx')
                           ->alias('a')
                           ->join('bm_goods b ON a.g_id=b.id','LEFT')
                           ->join('bm_goods_foundation c ON b.gx_id=b.gx_id','LEFT')
                           ->join('bm_qudao d ON c.dtypename = d.qudao_id','LEFT')
                           ->field('min(min_lx) as new_min_lx,max(max_lx) as new_max_lx,min(min_ed) as new_min_ed,max(max_ed) as new_max_ed,d.qudao_id,d.qudao_type')
                           ->group('qudao_type')
                           ->where($where_link)
                           ->select();
                foreach ($qudao as $y => $e) {
                   foreach ($link_data as $ey => $ue) {
                      if($e['qudao_type']==$ue['qudao_type']){
                         $qudao[$y]['m_data']=$ue;
                         break;
                      }
                   }
                }
    }
    /**
     * new评估辅助2
     * @DateTime:    [2018-03-13 11:12:25]
     */
    public function new_fz_biaoqian(){
      if($_POST){
          $where_link['b.daleiID']=$_POST['daleiid']?$_POST['daleiid']:'169';
          $where_link['c.gx_id']=array('gt','0');
          $link_data=M('lx')
                     ->alias('a')
                     ->join('bm_goods b ON a.g_id=b.id','LEFT')
                     ->join('bm_goods_foundation c ON b.gx_id=c.gx_id','LEFT')
                     ->where($where_link)
                     ->field('a.*,c.*')
                     ->select();
          $my_temp['min_lx']=$link_data[0]['min_lx'];
          $my_temp['max_lx']=$link_data[0]['max_lx'];
          $my_temp['min_ed']=$link_data[0]['min_ed'];
          $my_temp['max_ed']=$link_data[0]['max_ed'];
          foreach ($link_data as $k => $v) {
             if($link_data[$k]['min_lx']<$my_temp['min_lx']){
                $my_temp['min_lx']=$link_data[$k]['min_lx'];
             }
             if($link_data[$k]['max_lx']>$my_temp['max_lx']){
                $my_temp['max_lx']=$link_data[$k]['max_lx'];
             }
             if($link_data[$k]['min_ed']<$my_temp['min_ed']){
                $my_temp['min_ed']=$link_data[$k]['min_ed'];
             }
             if($link_data[$k]['max_ed']>$my_temp['max_ed']){
                $my_temp['max_ed']=$link_data[$k]['max_ed'];
             }
          }
          $link_data['my_lx_data']=$my_temp;
          $msg['code']=1;
          $msg['message']='查询成功';
          $msg['data']=$my_temp;
          $msg['link']=$link_data;
      }
      else{
        $msg['code']=2;
        $msg['message']='请求方式错误';
      }
      $this->ajaxReturn($msg);
         

    }
    /**
     * 下一步评估
     *
     *[0]='必须工薪';
     *[1]='8510,8526,8527';
     *[2]='小额贷款,银行';
     *[3][0]=房产抵用类,工薪抵用类
     *[3][1]="155,15";
     *[4]='';
     *[5][0]=0/1 （0顺序，1倒序）
     *[5][1]=ed/lx (额度/利息)
     */
    public function text(){
          $res_temp=D('WebUser')->m_data($_POST);
          $where_qudao_goods['cpclass']=array('like', $res_temp);
    }
    public function next_pingu(){
        if($_POST){
            $goods=M('goods');
            $arr=$_POST;
            if(is_array($arr[0])){
                $res_data=D('WebUser')->next_pingu(1,$arr);
                session('search_data',$res_data);
            }
            else{
                $res_data=D('WebUser')->next_pingu(2,$arr);
                session('search_data',$res_data);
            }

                $this->assign('biaoqian',$res_data);
        /***************按揭员渲染******************/
                $where_web['web_id']=array('neq',$_SESSION['user']['web_id']);
                if($_SESSION['user']['web_type']==1){

                    $where_web['p_u_id']=$_SESSION['user']['p_u_id'];
                    $where_web['web_type']=1;
                    $web_user=M('web_user')->where($where_web)->select();
                    $this->assign('web_user_list',$web_user);

                }
                else{

                    $where_web['p_u_id']=$_SESSION['user']['p_u_id'];
                    $where_web['web_type']=1;
                    $web_user=M('web_user')->where($where_web)->select();
                    $this->assign('web_user_list',$web_user);
                    
                }
        /***************按揭员渲染******************/
              
        }
       $this->display();
    }

    /**
     * 评估结果页面(无用)
     */
    public function panel_search(){
 
     $bq=M('biaoqian');
     for ($i=1; $i <8 ; $i++) { 
         $where_biaoqian['type']=$i;
         $biaoqian_data[$i]=$bq->where($where_biaoqian)->select();
         
     }
     foreach (session('search_data') as $key => $value) {
        $biaoqian_temp[$key]['revenue']=$value['revenue'];
        $biaoqian_temp[$key]['jinjian']=$value['jinjian'];
        $biaoqian_temp[$key]['lx']=$value['lx'];
        $biaoqian_temp[$key]['assessment']=$value['assessment'];
        $biaoqian_temp[$key]['datami']=$value['datami'];
        $biaoqian_temp[$key]['area']=$value['area'];
        $biaoqian_temp[$key]['especial']=$value['especial'];
        $forbin[$key]=$value['forbade'];
     }
     $temp_forbin_arr=array();
     foreach ($forbin as $k_forbin => $v_forbin) {
           foreach (explode(',',$v_forbin) as $k_t_y => $v_t_e) {
              array_push($temp_forbin_arr,$v_t_e);
           }
     }
     foreach ($biaoqian_data as $key_temp => $value_temp) {
         foreach ($value_temp as $k_temp => $v_temp) {
             if($key_temp==1){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='revenue'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
             if($key_temp==3){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='lx'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
             if($key_temp==4){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='assessment'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
             if($key_temp==5){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='datami'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
             if($key_temp==6){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='area'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
             if($key_temp==7){
                 foreach ($biaoqian_temp as $bq_key_temp => $bq_value_temp) {
                      foreach ($bq_value_temp as $bq_k_temp => $bq_v_temp) {
                           if($bq_k_temp=='especial'){
                              $temp_bq_data_arr=explode(',',$bq_v_temp);
                              if(in_array($v_temp['id'],$temp_bq_data_arr)){
                                 $biaoqian_data[$key_temp][$k_temp]['state']=1;
                              }
                           }
                           unset($temp_bq_data_arr);

                      }
                 }
             }
         }
     }
     $this->assign('forbin',array_unique($temp_forbin_arr));
     $this->assign('biaoqian_temp',json_encode($biaoqian_temp));
     unset($biaoqian_data[2]);
     $this->assign('biaoqian_data',$biaoqian_data);
     $this->assign('search',session('search_data'));
     $this->display();
    }
    /**
     * 最终查询接过
     */
    public function last_product(){
        /**
         * 列表进入数据
         */
        if($_GET){
            if($_GET['search_data']&&$_GET['chat_id']&&$_GET['c_id']){
                $search_data=$_GET['search_data'];
                $where1['chat_id']=$_GET['chat_id'];
                $where2['c_id']=$_GET['c_id'];
                $chat=M('chat')->where($where1)->find();
                $my_kuhu=M('web_user_data')->where($where2)->find();
                if($chat&&$my_kuhu){
                    session('chat',$chat);
                    session('my_kuhu',$my_kuhu);
                    session('list_search_data',json_decode($search_data,true));
                    if($_SESSION['role']['state']==0&&$_GET['role']){
                       unset($_SESSION['role']);
                       $role_data['state']=0;
                       $role_data['role']=1;
                       session('role',$role_data);
                    }
                    $arr=json_decode($search_data,true);
                }
                else{
                    $this->show("<h1>404</h1>");die;
                }

            }
            else{
                $this->show("<h1>404</h1>");die;
            }

        }
        elseif ($_POST) {
            $arr=$_POST;
        }
        if($arr){
            $goods=M('goods');
            if(is_array($arr[0])){
                $res_data=D('WebUser')->next_pingu(1,$arr,1);
            }
            else{
                $res_data=D('WebUser')->next_pingu(2,$arr,1);
            }
                session('search_data',$res_data);
        }

        $this->display();
    }
    /**
     * 业务员第一次咨询银行职员评估资料上传
     */
    public function panel_p_data(){
        if($_POST){
          $arr['data']=$_POST['data'];
          $arr['kehu_name']=$_POST['kehu_name'];
          $arr['link']=$_POST['file'];
          $arr['time']=date('Y年m月d日 h:i:s');
          $arr['group']=$_SESSION['user']['web_id'];
          $where_kuhu['c_id']=$_SESSION['my_kuhu']['c_id'];
          if($arr['data']){
              $res=M('web_user_data')->where($where_kuhu)->save($arr);



              if($res){
                      $my_kuhu=M('web_user_data')->where('c_id='.$_SESSION['my_kuhu']['c_id'])->find();
                      session('my_kuhu',$my_kuhu);
                      /*******************聊天室生成*********************/
                       if(!session('chat')){
                           $chat=D('Chat')->add_chat();
                        }
                      /*******************聊天室生成*********************/
                      /***************开始链表存储处理客户申请资料***********************/
                       if(!session('shenqing')){
                        $apply['c_id']=$_SESSION['my_kuhu']['c_id'];
                        $cd_id=M('shenqing')->data($apply)->add();
                        $my_shenqing=M('shenqing')->where('cd_id='.$cd_id)->find();
                        session('shenqing',$my_shenqing);
                        /**
                         * 4表关联存储 用户申请
                         */
                        $lccdc_data_apply['lccdc_id']=session('my_lccdc.lccdc_id');
                        $lccdc_data_apply['cd_id']=$cd_id;
                        $lccdc=M('lccdc')->save($lccdc_data_apply);
                        $my_lccdc_apply=M('lccdc')->where('lccdc_id='.session('my_lccdc.lccdc_id'))->find();
                        session('my_lccdc',$my_lccdc_apply);
                        }
                        /***************开始链表存储处理客户申请资料***********************/
                        /****************咨询条件存储************************/
                       if(!session('my_search_data')){

                            $my_search_data['web_id']=$_POST['search_data']['web_id'];
                            $my_search_data['search_data']=$_POST['search_data']['data'];
                            $my_search_data['c_id']=$_SESSION['my_kuhu']['c_id'];
                            $data_id=M('search_data')->data($my_search_data)->add();
                            $my_search_data_new=M('search_data')->where('data_id='.$data_id)->find();
                            session('my_search_data',$my_search_data_new);
                            /**
                             * 4表关联存储 用户申请
                             */
                            $lccdc_search['lccdc_id']=session('my_lccdc.lccdc_id');
                            $lccdc_search['data_id']=$data_id;
                            $lccdc=M('lccdc')->save($lccdc_search);
                            $my_lccdc_search_data=M('lccdc')->where('lccdc_id='.session('my_lccdc.lccdc_id'))->find();
                            session('my_lccdc',$my_lccdc_search_data);

                            /***************开始链表存储处理客户申请资料***********************/

                        }
                        /****************咨询条件存储************************/
              }

        }
         $this->assign('web_data',$_SESSION['my_kuhu']);
         $this->display('WebUser/panel_p_data_return');
        }
        else{
        $this->assign('web_data',$_SESSION['my_kuhu']);
        $this->display();
        }
    }
    /**
     * ajax接受文件
     */
    public function ajax_re_file(){
          if ($_FILES["file"]["size"] < 2000000){
            if ($_FILES["file"]["error"] > 0){
                $msg['code']=2;
                $msg['message']='错误';
              }
            else{
                $msg=D('WebUser')->upload_img('web_user_data');
              }
          }
          else{
            $msg['code']=3;
            $msg['message']='文件过大';
          }
          $this->ajaxReturn($msg);
    }

        /**
     * 密码更新
     * @return [type] [description]
     */
    public function update_passwd(){
        if($_POST){
            if($_POST['old_password']==$_POST['new_password']){
                $this->error('新旧密码不可以相同');
            }
            elseif ($_POST['old_password']&&$_POST['new_password']) {
                $user=$_SESSION['user'];
                /**
                 * 加密
                 */
                //$passwd['web_pass']=md5(md5($_POST['new_password']).$user['code']);
                /**
                 * 不加密
                 */
                $passwd['bind_id']='';//去除绑定
                $passwd['web_pass']=$_POST['new_password'];
                $where['web_id']=$user['web_id'];
                $res=M('user')->where($where)->save($passwd);
                if($res){
                    $message=D('User')->loginout(3);
                    session(null);
                    $this->success($message,U('index/index'));
                }
                else{
                    $this->error('更新失败');

                }

            }
            else{
                $this->error('请检查新旧密码是否填写');
            }
        }
        else{
            $this->display();
        }
    }
    /**
     * 
     * 详情搜索
     * 
     */
    public function next_pingu_alt(){
    /***************按揭员渲染******************/
            $where_web['web_id']=array('neq',$_SESSION['user']['web_id']);
            if($_SESSION['user']['web_type']==1){
               

                $where_web['p_u_id']=$_SESSION['user']['p_u_id'];
                $where_web['web_type']=1;
                $web_user=M('web_user')->where($where_web)->select();
                $this->assign('web_user_list',$web_user);

            }
            else{

                $where_web['p_u_id']=$_SESSION['user']['p_u_id'];
                $where_web['web_type']=1;
                $web_user=M('web_user')->where($where_web)->select();
                $this->assign('web_user_list',$web_user);
                
            }
    /***************按揭员渲染******************/
        $this->display();
    }
    /**
     *  按揭员显示特殊页面(按揭员作为检测方显示)
     */
    public function aj_chat(){
        $this->display();
    }

    /**
     * 判断银行职员是否有加入聊天室
     */
    public function ck_yh_chat(){
      if(true){
        $where1['id']=$_POST['goods_id']?$_POST['goods_id']:41;
        $where2['qudao_id']=$_POST['qudao_id']?$_POST['qudao_id']:1;
        $where3['chat_id']=$_POST['chat_id']?$_POST['chat_id']:'';
        /*****************对应渠道原数据***********************/
        $res_qudao_list=M('web_user')->where($where2)->select();
        /*****************原数据判断是否存在聊天室***********************/
        $i=0;
        foreach ($res_qudao_list as $key => $value) {
             $ck_where['yh']=$value['web_id'];
             $ck_where['chat_id']=$_POST['chat_id'];
             $ck_where['goods_id']=$value['goods_id'];
             $rk_data=M('chat_group')->where($ck_where)->find();
             if($rk_data){
               $res_data[$i]=$value;
               $res_data[$i]['ck_chat_group']=1;
             }
             else{
               $res_data[$i]=$value;
               $res_data[$i]['ck_chat_group']=0;
             }
             $i++;


        }
        $msg['code']=1;
        $msg['message']='请求成功';
        $msg['data']=$res_data;
      }
      else{
        $msg['code']=2;
        $msg['message']='请求方式错误';
      }
      $this->ajaxReturn($msg);
    }
    /**
     * 异步获取商品信息
     */
    public function pro_detail_page(){
      $where['id']=$_POST['g_id'];
      $where1['g_id']=$_POST['g_id'];
      $res_data=M('goods')
                ->alias('a')
                ->join('bm_goods_foundation b ON a.gx_id=b.gx_id','LEFT')
                ->where('a.id='.$where['id'])
                ->field('a.*,b.name as f_name,b.qudaoname as f_qudaoname,b.bzname as f_bzname,b.dtypename as f_dtypename')
                ->find();

      $where_goods['color_goods_id']=$res_data['color_goods_id'];
      $res_data['my_color_data']=M('goods_color')->where($where_goods)->find();
      $res_data['my_lx_data']=M('lx')->where($where1)->select();
      foreach ($res_data['my_lx_data'] as $key => $value) {
          $where_lx['color_lx_id']=$value['color_lx_id'];
          $res_data['my_lx_data'][$key]['lx_color_data']=M('lx_color')->where($where_lx)->find();
          unset($where_lx);
      }
      $res_data['my_csee_data']=M('cinv_see')->where($where1)->select();
      $res_data['my_ctimes_data']=M('cinv_times')->where($where1)->select();
      $res_data['my_gdiy_data']=M('goods_diy_name')->where($where1)->find();
      $res_data['my_goods_diy_name']=M('goods_ad')->where($where1)->find();
      $res_data['my_goods_link']=M('goods_link')->where($where1)->select();
      $where2['tj_g_id']=$_POST['g_id'];
      $ajtj=M('ajtj')->where($where2)->select();
      
      if(count($ajtj)){
        foreach ($ajtj as $key => $value) {
              $res_data['my_ajtj'].='<div class="textTitle"><span>'.get_nave_ajtj($value['tj_g_id'],$value['tj_web_id']).'</span></div><div class="yiban">'.(M('ajtj')->where(array('tj_g_id'=>$value['tj_g_id'],'tj_web_id'=>$value['tj_web_id']))->getField('tj_reason')).'</div>'; 
          if($key<count($ajtj)-1){
              $res_data['my_ajtj']='<div class="textTitle"><span>'.get_nave_ajtj($value['tj_g_id'],$value['tj_web_id']).'</span></div><div class="yiban">'.(M('ajtj')->where(array('tj_g_id'=>$value['tj_g_id'],'tj_web_id'=>$value['tj_web_id']))->getField('tj_reason')).'</div>'.'&';
          }
        }
      }
      $arr_ajtj=explode('&', $res_data['my_ajtj']);
      $res_data['my_ajtj']=implode(' ',$arr_ajtj);
      if(count($arr_ajtj)>3){
         for ($kh=3; $kh <count($arr_ajtj) ; $kh++) { 
             unset($arr_ajtj[$kh]);
         }
         $res_data['my_ajtj']=implode(' ',$arr_ajtj);
      }
      $this->assign('message',$res_data);
      $res=$this->fetch();
      echo $res;

    }

    /**
     * ajax单独渲染银行职员
     */
    public function ajax_re_chat(){
       if(IS_AJAX&&IS_POST){
            $where['goods_id']=$_POST['goods_id'];
            $extends_data=M('chat_group')
                         ->alias('a')
                         ->join('bm_from_user_group z ON a.chat_id=z.chat_id')
                         ->join('bm_chat b ON a.chat_id=b.chat_id')
                         ->join('bm_lccdc c ON b.chat_id=c.chat_id')
                         ->join('bm_web_user_data d ON c.c_id=d.c_id')
                         ->where('a.goods_id='.$where['goods_id'].' and a.y_id='.session('user.web_id'))
                         ->field('z.*,b.*,b.*,d.*,a.*')
                         ->group('c.lccdc_id')
                         ->select();
            foreach ($extends_data as $key => $value) {
                        $where_web['web_id']=$value['first_user'];
                        $extends_data[$key]['aj_data']=M('web_user')->where($where_web)->field('web_name,web_phone')->find();
            }
            if($extends_data){
               $msg['code']=1;
               $msg['message']='请求成功';
               $msg['data']=$extends_data;
               $msg['data1']=$_POST['goods_id'];


            }
            else{
              $msg['code']=2;
              $msg['message']='没有聊天数据';
            }
       }
       else{
          $msg['code']=3;
          $msg['message']='请求方式有误';
       }
       $this->ajaxReturn($msg);
    }

}


